<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .container{
        width: 300px;height: 300px;
        margin: 100px auto;
        position: relative;
    }
    .container>div{
        width: 300px;height: 300px ;
        position: absolute;
        transition: all 3s;
        backface-visibility: hidden;
    }
    .front{
        background-color: salmon;
        z-index: 999;
        animation: toback 2s infinite;
    }
    /* .back{
        transform: rotateY(-180deg);
    } */
    /* .container:hover .front{
        transform: rotateY(180deg);
    }
    .container:hover .back{
        transform: rotateY(0deg);
    } */
    .back{
        height: 300px;
        background-color: skyblue;
        animation: tofront 2s infinite;
    }
    @keyframes toback{
        0% {transform: rotateY(0deg);}
        50% {transform: rotateY(180deg);}
        100% {transform: rotateY(360deg);}
    }
    @keyframes tofront{
        0% {transform: rotateY(-180deg);}
        50% {transform: rotateY(0deg);}
        100% {transform: rotateY(180deg);}
    }
    </style>
</head>
<body>
    <div class="container">
        <div class="front"></div>
        <div class="back"></div>
    </div>
</body>
</html>